#include <iostream>

using namespace std;

const int N = 100010;

int m;
int stk[N],tt;

int main()
{
    cin >> m;
    while(m--)
    {
        int n;
        cin >> n;
        while(n--)
        {
        	string op;
        int x;
        
        cin >> op;
        if(op=="push")
        {
            cin >> x;
            stk[++tt] = x;
        }
        else if(op=="pop")
        {
        	if(tt) tt--; 
        	else cout << "Empty" << endl;
		}

        else if(op=="empty") cout << (tt ? "NO" : "YES" ) << endl;

        else if(op=="query")
        {
        	if(tt) cout << stk[tt] << endl;
        	else cout << "Anguei!" << endl;
		}
        
        else cout << tt << endl;
		}
    }
}
